package com.zhw.controller;

import com.zhw.pojo.entry.Customer;
import com.zhw.pojo.dto.CustomerQueryDTO;
import com.zhw.pojo.PageBean;
import com.zhw.pojo.Result;
import com.zhw.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("customer")
@Slf4j
public class CustomerInfoController {
    @Autowired
    CustomerService customerService;

    @GetMapping("page")
    public Result page(CustomerQueryDTO customerQueryDTO){
      log.info("分页查询客户数据：{}",customerQueryDTO);
        PageBean pb=customerService.page(customerQueryDTO);
        return Result.success(pb);
    }


    @GetMapping("getAddresses")
    public Result getAddresses(){
        log.info("查询当前所有用户的地区信息");

        List<Map<String,String>> getAddresses=customerService.getAddresses();
        return Result.success(getAddresses);

    }

    @PostMapping("save")
    public Result save(@RequestBody Customer customer){
        log.info("添加一个新的客户：{}",customer);
        customerService.save(customer);
        return Result.success();
    }



    @GetMapping("getCustomerById")
    public Result getById(Integer id){
        log.info("查询ID：{}客户",id);
        Customer c=customerService.getByID(id);
        return Result.success(c);
    }

    @PutMapping("update")
    public Result update(@RequestBody Customer c){
        log.info("修改当前用户信息：{}",c);
        customerService.update(c);
        return Result.success();
    }



    @DeleteMapping("deleteByID")
    public Result deleteByID(Integer id){
        log.info("根据ID删除一个客户：{id}",id);
        customerService.delete(id);
        return Result.success();
    }


    @GetMapping("getCustomerName")
    public Result getCustomerName(){
        log.info("查询所有用户的姓名");
        List<Map<String,String>> list=customerService.getCustomerName();
        return Result.success(list);
    }
}
